package cn.ubeta.b2c.utils;

import android.util.Log;

import cn.ubeta.b2c.BuildConfig;

/**
 * Created by anlijun on 15/6/24.
 */
public class Dlog {
    public static final String TAG = "JdStaging";
    private static boolean mOpen = BuildConfig.DEBUG;

    public static void switchLog(boolean open) {
        mOpen = open;
        if (mOpen) {
            Log.e(getLogTag(), "switch log on");
        }
    }

    public static void w(String msg) {
        if (mOpen) {
            Log.w(getLogTag(), msg);
        }
    }

    public static void e(String msg) {
        if (mOpen) {
            Log.e(getLogTag(), msg);
        }
    }
    public static void d(String msg) {
        if (mOpen) {
            Log.d(getLogTag(), msg);
        }
    }

    /**
     * 获取类名与方法名
     */
    private static String getLogTag() {
        StringBuilder tag = new StringBuilder();
        tag.append(TAG);
        try {
            StackTraceElement stes[] = Thread.currentThread().getStackTrace();
            StackTraceElement ste = stes[4];
            tag.append("(").append(ste.getFileName()).append(":").append(ste.getLineNumber()).append(")");
//            tag.append("_").append("(").append(fileName.substring(0, fileName.lastIndexOf("."))).append(":").append(ste.getMethodName()).append(":").append(ste.getLineNumber()).append(")");
        } catch (Exception e) {
        }
        return tag.toString();
    }
}
